import actionType from '../actionType'
import {handleActions} from 'redux-actions'


// 登录
const loginState = () => ({})
const loginActions = {}

loginActions[actionType.REQUEST_LOGIN] = (state, action) => {
    console.log(state)
    console.log(action)
    return { ...state, loading: true }
}
loginActions[actionType.RECEIVE_LOGIN] = (state, action) => {
    console.log(state)
    console.log(action)
    const { req, res } = action.payload
    return { data: res, loading: false }
}
export const loginResponse = handleActions(loginActions,loginState())

// 表单功能
const cacheState = () => ({})
const cacheActions = {}
cacheActions[actionType.SET_FORM_CACHE] = (state, action) => {
    console.log(state)
    console.log(action)
    const { cacheKey, cacheContent } = action.payload
    if (cacheKey === undefined) {
        throw new Error('cacheKey不能是undefined')
    }
    if (cacheContent === undefined) {
        throw new Error('cacheContent不能是undefined')
    }
    state[cacheKey] = { ...state[cacheKey], ...cacheContent }
    return { ...state }
}
cacheActions[actionType.CLEAR_FORM_CACHE] = (state, action) => {
    console.log(state)
    console.log(action)
    return cacheState()
}
export const formCache = handleActions(cacheActions,cacheState())

